//购物车仓库
import { defineStore } from "pinia";
export const useCartData =  defineStore('shopcar',{
    state:()=>{
        return{
            shopcar:[],
            
        }
    },
    getters:{
    },
    actions:{
        //加入购物车；
        addCar(value){
            var findIndex = this.shopcar.findIndex(item=>item.id==value.id);
            if(findIndex===-1){
                value.count = 1
                this.shopcar.push(value)
            }else{
                this.shopcar[findIndex].count++
            }
            
            
        },
        
    },
    
    
    persist:{
        key:'shopCarData',
        storage:localStorage,
        
    }

})